package com.yuwei.goods_detail


import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.flexbox.FlexboxLayoutManager
import com.yuwei.base.RoutePath
import com.yuwei.common.mvi.BaseMviActivity
import com.yuwei.common.mvi.UiState
import com.yuwei.goods_detail.adapter.CommentTopTypeAdapter
import com.yuwei.goods_detail.adapter.DetailCommentAdapter
import com.yuwei.goods_detail.databinding.ActivityCommentBinding
import com.yuwei.goods_detail.entity.CommentUserEntity

/**
 * 游戏鸿蒙-i视频-05-商品详情V1.1-20260613-崔志彪
 */
@Route(path = RoutePath.GOODS_COMMENT)
class CommentActivity : BaseMviActivity<ActivityCommentBinding, GoodsDetailViewModel>() {
    private var commentTopTypeAdapter = CommentTopTypeAdapter()
    private var commentDetailAdapter = DetailCommentAdapter()
    private var mPosition = 0
    private var itemId = "6936590061114753549"
    override fun successData(it: UiState.onSuccess<*>) {
        when(it.type){
            "getComment"->{
                commentDetailAdapter.data.clear()
                commentDetailAdapter.data.addAll(it.data as CommentUserEntity)
                commentDetailAdapter.notifyDataSetChanged()
            }
        }
    }

    override fun failureData(error: String) {

    }

    override fun initView() {
        binding.commentTopTypeRv.adapter = commentTopTypeAdapter
        binding.commentTopTypeRv.layoutManager = FlexboxLayoutManager(this)

        commentTopTypeAdapter.data.add("全部")
        commentTopTypeAdapter.data.add("好评")
        commentTopTypeAdapter.data.add("中评")
        commentTopTypeAdapter.data.add("差评")
        commentTopTypeAdapter.data.add("值得学习")
        commentTopTypeAdapter.data.add("质量超好")
        commentTopTypeAdapter.notifyDataSetChanged()
        commentTopTypeAdapter.setOnItemClickListener { adapter, view, position ->
            mPosition = position
            commentTopTypeAdapter.setPosition(mPosition)
            commentTopTypeAdapter.notifyDataSetChanged()
            when (position) {
                0 -> itemId = "6936590061114753549"
                1 -> itemId = "7055998662333334046"
                2 -> itemId = "6984351555034022414"
                3 -> itemId = "6982822113786888711"
                4 -> itemId = "7034821008162816520"
                5 -> itemId = "6962968068267967013"
            }
            //评论列表
            binding.commentRv.adapter = commentDetailAdapter
            binding.commentRv.layoutManager = LinearLayoutManager(this)
            vm.handleIntent(GoodsDetailIntent.getComment(0,itemId))
        }
        if (mPosition == 0){
            //评论列表
            binding.commentRv.adapter = commentDetailAdapter
            binding.commentRv.layoutManager = LinearLayoutManager(this)
            vm.handleIntent(GoodsDetailIntent.getComment(0,itemId))
        }
        //返回
        binding.commentBack.setOnClickListener { 
            finish()
        }

    }

    override fun initData() {

    }

}